//
//  rotate_rect.hpp
//  OpenLearn
//
//  Created by korion chen on 2020/3/20.
//  Copyright © 2020 korion. All rights reserved.
//

#ifndef rotate_rect_hpp
#define rotate_rect_hpp

#include <stdint.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

class RotateRect {
    static const float vertices[32];
        
        static const uint32_t index[6];
        
        const char* vertex_shader_code = ""
            "#version 330 core\n"
            "layout (location = 0) in vec3 pos;\n"
            "layout (location = 1) in vec3 color;\n"
            "layout (location = 2) in vec2 texPos;\n"
            "out vec3 ourColor;\n"
            "out vec2 TexPos;\n"
            "uniform mat4 matrix;\n"
            "void main()\n"
            "{\n"
            "    gl_Position = matrix * vec4(pos, 1.0);\n"
            "    ourColor = color;\n"
            "    TexPos = texPos;\n"
            "}\n";
        
        const char* fragment_shader_code = ""
            "#version 330 core\n"
            "in vec3 ourColor;\n"
            "in vec2 TexPos;\n"
            "out vec4 FragColor;\n"
            "uniform float tran;\n"
            "uniform sampler2D texture0;\n"
            "uniform sampler2D texture1;\n"
            "void main()\n"
            "{\n"
            "    FragColor = mix(texture(texture0, TexPos), texture(texture1, TexPos), tran);\n"
            "}\n";
        
        uint32_t VBO;
        
        uint32_t VAO;
        
        uint32_t EBO;
        
        uint32_t mProgram;
        
        uint32_t texture0;
        
        uint32_t texture1;

        bool hasInit = false;
        
        int createShader(int, const char*);
        int createProgram();
        int loadTexture(const char*, bool);
        glm::mat4 getTransMatrix(float);
        
    public:
        bool init();
        
        void drawSelf(GLFWwindow *window, float);
        
        void destroy();
    
};

#endif /* rotate_rect_hpp */
